import java.util.List;
import java.awt.image.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import static java.awt.GraphicsDevice.WindowTranslucency.*;

public class MainClientUI extends JFrame implements ActionListener{
	
	private GridBagConstraints gbc = new GridBagConstraints();
	
    private JFrame mainFrame = new JFrame();
    private Dimension mainFSize,screenSize;
    private ImageIcon img1;
    private ImageIcon clientButtonPressed,exitButtonPressed;
    private Icon clientButton1a,exitButton1a;
    private JPanel mainPaneTop,mainPaneBottom;
    private ImageButton clientButton,exitButton;
       
    public MainClientUI() throws Exception{
    	img1 = new ImageIcon("clientMain.png");
    	mainFSize = new Dimension(img1.getIconWidth(),img1.getIconHeight());
    	mainFrame.setPreferredSize(mainFSize);
		mainFrame.setResizable(false);
		
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int x = ((int)screenSize.getWidth()/2)-200;
		int y = ((int)screenSize.getHeight()/2)-200;
		setLocation(x,y);
		
		mainPaneTop = new JPanel(){
            public void paintComponent(Graphics g){
                Image img = new ImageIcon("clientMain.png").getImage();
                Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                setPreferredSize(size);
                setMinimumSize(size);
                setMaximumSize(size);
                setSize(size);
                setLayout(null);
                g.drawImage(img, 0, 0, null);
            }
        };
        mainPaneTop.setBounds(0, 0, img1.getIconWidth(), img1.getIconHeight());
        
        mainPaneBottom = new JPanel(new GridBagLayout());
		mainPaneBottom.setOpaque(false);
         
        clientButton = new ImageButton("button2.png");
        clientButton1a = new ImageIcon("button2a.png");
        clientButtonPressed = new ImageIcon("button2b.png");
		clientButton.setRolloverIcon(clientButton1a);
	    clientButton.setPressedIcon(clientButtonPressed);
        clientButton.setBorder(null);
        clientButton.setContentAreaFilled(false);
        gbc.gridx = 0;
		gbc.gridy = 0;
        gbc.insets = new Insets(-270,78,0,50);
        clientButton.addActionListener(this);
        
        
        mainPaneBottom.add(clientButton,gbc);
         
        exitButton = new ImageButton("exit.png");
        exitButton1a = new ImageIcon("exit1a.png");
        exitButtonPressed = new ImageIcon("exit1b.png");
		exitButton.setRolloverIcon(exitButton1a);
		exitButton.setPressedIcon(exitButtonPressed);
        exitButton.setBorder(null);
        exitButton.setContentAreaFilled(false);
        gbc.gridx = 0;
		gbc.gridy = 1;
        gbc.insets = new Insets(-80,78,0,50);
        exitButton.addActionListener(this);
        mainPaneBottom.add(exitButton,gbc);
         
        mainFrame.setUndecorated(true);
	 	mainFrame.setBackground(new Color(0,0,0,0));
	    mainFrame.setResizable(false);
	    mainFrame.add(mainPaneTop);
		mainFrame.add(mainPaneBottom);
		mainFrame.setLocation(x-30,y-25);
	    mainFrame.setSize(750,450);
	    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    mainFrame.setVisible(true);
    }
    
    class ImageButton extends JButton {
  		public ImageButton(String img) {
    		this(new ImageIcon(img));
   		}

  		public ImageButton(ImageIcon icon) {
		    setIcon(icon);
		    setMargin(new Insets(0, 0, 0, 0));
		    setIconTextGap(0);
		    setBorderPainted(false);
		    setBorder(null);
		    setText(null);
		    setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
  		}
	}
	
	public void actionPerformed(ActionEvent event){  	
			if(event.getSource().equals(clientButton)){
		  		try{
		  			Client c = new Client();
		  			c.run();
		  		}catch(Exception e){
		  		}
		  	}else if(event.getSource().equals(exitButton)){
		  		mainFrame.dispose();
		  		System.exit(0);
		  	}	        
	}
    public static void main (String[] args)throws Exception {
        MainClientUI gui = new MainClientUI();
        
    }
}
